import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class demo02 {
    public static void main(String[] args) {
//      1、1池1线程
//        ExecutorService pool1=Executors.newSingleThreadExecutor();
//        pool1.submit(new Runnable() {
//            @Override
//            public void run() {
//                System.out.println("hello1");
//            }
//        });

//        2、1池n线程
//        ExecutorService pool2= Executors.newFixedThreadPool(10);
//        pool2.submit(new Runnable() {
//            @Override
//            public void run() {
//                System.out.println("hello2");
//            }
//        });

//        3、1池可扩容可回收线程
//        ExecutorService pool3=Executors.newCachedThreadPool();
//        pool3.submit(new Runnable() {
//            @Override
//            public void run() {
//                System.out.println("hello3");
//            }
//        });

//        4、支持定时和周期性任务执行
        ScheduledExecutorService pool4=Executors.newScheduledThreadPool(5);
        pool4.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                System.out.println("hello4");
            }
        },1,3, TimeUnit.SECONDS);
    }
}





